package manager;

import entity.Subject;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class SubjectManager implements IManager<Subject> {

    private ArrayList<Subject> subjectsList;

    public SubjectManager() {
        this.subjectsList = new ArrayList<Subject>();
    }

    @Override
    public boolean add(Subject subjects) {
        return this.subjectsList.add(subjects);
    }

    @Override
    public boolean remove(Subject subjects) {
        return this.subjectsList.remove(subjects);
    }

    @Override
    public Subject replace(int index, Subject subjects) {
        return this.subjectsList.set(index, subjects);
    }

    @Override
    public int size() {
        return this.subjectsList.size();
    }

    @Override
    public Subject get(int index) {
        return this.subjectsList.get(index);
    }

    @Override
    public Subject getById(int subjectID) {
        for (Subject subject : this.subjectsList) {
            if (subject.getSubjectID() == subjectID) {
                return subject;
            }
        }
        return null;
    }

    @Override
    public Subject getByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public ArrayList<Subject> getSubjectsByClassRoomBlockId(int classRoomBlockID) {
        ArrayList<Subject> alSubjects = new ArrayList();
        for(int i = 0; i < this.subjectsList.size(); i++) {
            if(this.subjectsList.get(i).getClassRoomBlockID() == classRoomBlockID) alSubjects.add(this.subjectsList.get(i));
        }
        return alSubjects;
    }
    
    @Override
    public void setVisible(Subject obj, boolean value) {
        for (Subject subject : this.subjectsList) {
            if (obj.getSubjectID() == subject.getSubjectID()) {
                subject.setStatus(value);
            }
        }
    }

    public Subject contains(Subject obj) {
        for (Subject object : this.subjectsList) {
            if ((object.getSubjectName().equals(obj.getSubjectName())) && (object.getClassRoomBlockID() == obj.getClassRoomBlockID())) {
                return object;
            }
        }
        return null;
    }

    public int indexOf(Subject subject) {
        return this.subjectsList.indexOf(subject);
    }
}